﻿using AIVision.Model.EntityModels;
using AIVision.Repository.Services;
using Prism.Commands;
using Prism.Events;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace AIVision.UI.ViewModels
{
    public class SetPLCConfigViewModel: BindableBase
    {

        public DelegateCommand<string> BtnCommand { get; private set; }
        private PLCConfigDto plcConfig;
        private readonly IEventAggregator eventAggregator;
        private readonly PLCConfigService plcConfigService;

        public PLCConfigDto PLCConfig
        {
            get { return plcConfig; }
            set { plcConfig = value; RaisePropertyChanged(); }

        }

        public SetPLCConfigViewModel(IEventAggregator eventAggregator, PLCConfigService plcConfigService)
        {
            this.eventAggregator = eventAggregator;
            this.plcConfigService = plcConfigService;
            BtnCommand = new DelegateCommand<string>(BtnMethod);
            PLCConfig = plcConfigService.GetPLCConfig();
        }


        private void BtnMethod(string cmd)
        {
            try
            {
                plcConfigService.SavePLCConfig(PLCConfig);
                MessageBox.Show("保存成功!");
            }
            catch (Exception ex)
            {
                MessageBox.Show($"保存失败{ex.Message}");
            }

        }
    }
}
